<style>
    .xxpayPopupDiv .layui-form-label {
        width:120px !important;
        margin-left:1%;
    }
    .xxpayPopupDiv .layui-input-inline {
        width: 80% !important;
    }
</style>
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-tab layui-tab-brief">
            <div class="layui-tab-content">
                <form class="layui-form center">
                    <div class="layui-form-item">
                        <label class="layui-form-label">接口类型代码</label>
                        <div class="layui-input-inline">
                            <input type="text" name="ifTypeCode" id="ifTypeCode" placeholder="请输入接口类型代码" required lay-verify="required"  autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">接口类型名称</label>
                        <div class="layui-input-inline">
                            <input type="text" name="ifTypeName" id="ifTypeName" placeholder="请输入接口类型名称" required lay-verify="required"  autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">状态</label>
                        <div class="layui-input-inline" >
                            <input type="radio" name="status" title="开启" value="1" checked />
                            <input type="radio" name="status" title="关闭" value="0" />
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">支付子账号强制使用模板</label>
                        <div class="layui-input-inline" >
                            <input type="radio" name="mustFromTemplate" title="是" value="1" checked />
                            <input type="radio" name="mustFromTemplate" title="否" value="0" />
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label">支持的配置方式</label>
                        <div class="layui-input-inline" >
                            <input type="checkbox" id="supportConfigType_1" title="内置参数" checked/>
                            <input type="checkbox" id="supportConfigType_2" title="转卡通道银行卡" />
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label">备注信息</label>
                        <div class="layui-input-inline">
                            <input type="text" name="remark" placeholder="请输入备注信息" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">配置定义描述</label>
                        <div class="layui-input-inline">
                            <textarea name="param" id="param" placeholder="请输入配置定义描述" required lay-verify="required" class="layui-textarea"></textarea>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">回调IP白名单</label>
                        <div class="layui-input-inline">
                            <input name="whiteIp" id="whiteIp" placeholder="请输入回调IP白名单(多个半角逗号隔开)" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">订单超时时间(分钟)</label>
                        <div class="layui-input-inline">
                            <input name="orderExpire" id="orderExpire" placeholder="请输入订单超时时间(分钟)" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">支付确认金额（元）</label>
                        <div class="layui-input-inline">
                            <input type="text" name="payConfirmAmount" id="payConfirmAmount" placeholder="请输入支付确认金额" autocomplete="off" class="layui-input">
                            <span style="font-size: x-small;color: red">大于该金额需要人工确认到账，-1不限制</span>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">是否开启回调</label>
                        <div class="layui-input-inline" >
                            <input type="radio" name="enableNotify" title="开启" value="1" checked />
                            <input type="radio" name="enableNotify" title="关闭" value="0" />
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-input-block">
                            <button type="button" class="layui-hide xxpayYesBtn" lay-submit="" lay-filter="add">保存</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
<script>
    layui.use(['form','table','util','admin',],function(){
        var form = layui.form
        , $ = layui.$
        , admin = layui.admin
        , layer = layui.layer 
        , element = layui.element
        , table = layui.table;

        element.render('breadcrumb', 'breadcrumb');//渲染导航信息

        form.render();

        // 当点击微信渠道配置按钮保存的时候
        form.on('submit(add)', function(data){
            var ifTypeCode = $("#ifTypeCode").val();
            var orderExpire = $("#orderExpire").val();
            var reg = /^[0-9a-zA-Z_]{1,}$/;
            if(!reg.test(ifTypeCode)){
                layer.alert("接口类型代码只能输入字母、数字或下划线");
                return false;
            }
            var reg2 = new RegExp("^[0-9]*$");
            if(!reg2.test(orderExpire)){
                layer.alert("请输入正确的超时时间");
                return false;
            }

            var supportConfigType = "";

            if($('#supportConfigType_1').is(':checked')){ //支持 1
                supportConfigType += "1,";
            }
            if($('#supportConfigType_2').is(':checked')){ //支持 2
                supportConfigType += "2,";
            }

            if(!supportConfigType){
                layer.alert("请选择支持的配置方式！");
                return false;
            }

            var exp = /^(([1-9]\d*)|\d)(\.\d{1,2})?$/;
            if (data.field.payConfirmAmount != -1) {
                if(!exp.test(data.field.payConfirmAmount)){
                    layer.alert("请输入正确的金额");
                    return;
                }
                data.field.payConfirmAmount = data.field.payConfirmAmount * 100;
            }

            supportConfigType = supportConfigType.substr(0, supportConfigType.length - 1);
            data.field.supportConfigType = supportConfigType;

            admin.req({
                type: 'post',
                url: layui.setter.baseUrl + '/config/pay_interface_type/add', //模拟接口
                data: data.field,
                error: function(err){
                    layer.alert(err.msg,{title:"请求失败"})
                },
                success: function(res){
                    if(res.code == 0){
                        layer.alert(res.msg, {title: '保存成功'},function(index){
                            layer.closeAll(); //关闭所有弹层
                            layui.table.reload('tableReload', {page: {curr: 1}}); //调用业务弹层外表格重新加载
                        });
                    }
                }
            })
        })


    })
</script>